
/*-----------------------------------------------------------------------------\
|                            The Pomodoro technique                            |
|                                                                              |
| Developer: Felipe Simões Lage Gomes Duarte                                   |
|                                                                              |
| Main Project: The Pomodoro technique                                         |
| Date: 04 / oct / 2011                                                        |
| Code: Log.java                                                               |
| IDE: NetBeans IDE 7.0 (Build 201104080000)                                   |
| Java: 1.6.0_24; Java HotSpot(TM) Client VM 19.1-b02                          |
|                                                                              |
\-----------------------------------------------------------------------------*/

package interfaces;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 *
 * @author felipelageduarte
 */
public class Log extends javax.swing.JFrame {

   private static Log SINGLETON;
   private SimpleDateFormat sdf;

   /** Creates new form Log */
   private Log() {
      initComponents();
      FrameInTheMiddle.centerFrameOnScreen(this);
      sdf = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss");
   }

   public static synchronized Log getInstance() {
      if (SINGLETON == null) {
         SINGLETON = new Log();
      }
      return SINGLETON;
   }

   private synchronized void add(String type, String msg) {
      this.logTextArea.setText(this.logTextArea.getText() + "\n " + type + " --> "
              + sdf.format(new Date()) + '\n' + msg + "\n");
   }

   /*
    * Static Methods
    */
   public static synchronized void debug(String msg) {
      Log.getInstance().add("DEBUG", msg);
   }

   public static synchronized void info(String msg) {
      Log.getInstance().add("INFO", msg);
   }

   public static synchronized void warn(String msg) {
      Log.getInstance().add("WARN", msg);
   }

   public static synchronized void error(String msg) {
      Log.getInstance().add("ERROR", msg);
   }

   public static synchronized void fatal(String msg) {
      Log.getInstance().add("FATAL", msg);
   }

   @SuppressWarnings("unchecked")
   // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
   private void initComponents() {

      jScrollPane1 = new javax.swing.JScrollPane();
      logTextArea = new javax.swing.JTextPane();

      setTitle("Log");
      addWindowListener(new java.awt.event.WindowAdapter() {
         public void windowClosing(java.awt.event.WindowEvent evt) {
            formWindowClosing(evt);
         }
      });

      logTextArea.setEditable(false);
      jScrollPane1.setViewportView(logTextArea);

      javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
      getContentPane().setLayout(layout);
      layout.setHorizontalGroup(
         layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
         .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 600, Short.MAX_VALUE)
      );
      layout.setVerticalGroup(
         layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
         .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 250, Short.MAX_VALUE)
      );

      pack();
   }// </editor-fold>//GEN-END:initComponents

    private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
       this.setVisible(false);
    }//GEN-LAST:event_formWindowClosing
   // Variables declaration - do not modify//GEN-BEGIN:variables
   private javax.swing.JScrollPane jScrollPane1;
   private javax.swing.JTextPane logTextArea;
   // End of variables declaration//GEN-END:variables
}
